package com.edol.painting.painting;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.SparseArray;

import com.edol.painting.R;

public class Theme {
	
	public static final int THEME_DEFAULT = -1;
	public static final int THEME_PAPER_BACK_1 = 0;
	public static final int THEME_PAPER_BACK_2 = 1;
	public static final int THEME_PAPER_BACK_3 = 2;
	public static final int THEME_PAPER_BACK_4 = 3;
	public static final int THEME_PAPER_BACK_5 = 4;
	public static final int THEME_PAPER_BACK_6 = 5;
	public static final int THEME_PAPER_BACK_7 = 6;
	public static final int THEME_PAPER_BACK_8 = 7;
	public static final int THEME_PAPER_BACK_9 = 8;
	public static final int THEME_PAPER_BACK_10 = 9;
	public static final int THEME_PAPER_BACK_11 = 10;
	public static final int THEME_PAPER_BACK_12 = 11;
	public static final int THEME_PAPER_BACK_13 = 12;
	public static final int THEME_PAPER_BACK_14 = 13;
	public static final int THEME_PAPER_BACK_15 = 14;
	public static final int THEME_PAPER_BACK_16 = 15;
	public static final int THEME_ALL = 16;

	public int mId;
	public int mPaper;
	
	private static SparseArray<Bitmap> sPaperBitmap = new SparseArray<Bitmap>();
	
	public static final Theme[] THEME_LIST = new Theme[] {
		new Theme(Theme.THEME_PAPER_BACK_1, R.drawable.paper_back_one),
		new Theme(Theme.THEME_PAPER_BACK_2, R.drawable.paper_back_two),
		new Theme(Theme.THEME_PAPER_BACK_3, R.drawable.paper_back_three),
		new Theme(Theme.THEME_PAPER_BACK_4, R.drawable.paper_back_four),
		new Theme(Theme.THEME_PAPER_BACK_5, R.drawable.paper_back_five),
		new Theme(Theme.THEME_PAPER_BACK_6, R.drawable.paper_back_six),
		new Theme(Theme.THEME_PAPER_BACK_7, R.drawable.paper_back_seven),
		new Theme(Theme.THEME_PAPER_BACK_8, R.drawable.paper_back_eight),
		new Theme(Theme.THEME_PAPER_BACK_9, R.drawable.paper_back_nine),
		new Theme(Theme.THEME_PAPER_BACK_10, R.drawable.paper_back_ten),
		new Theme(Theme.THEME_PAPER_BACK_11, R.drawable.paper_back_eleven),
		new Theme(Theme.THEME_PAPER_BACK_12, R.drawable.paper_back_twelve),
		new Theme(Theme.THEME_PAPER_BACK_13, R.drawable.paper_back_thirteen),
		new Theme(Theme.THEME_PAPER_BACK_14, R.drawable.paper_back_fourteen),
		new Theme(Theme.THEME_PAPER_BACK_15, R.drawable.paper_back_fifteen),
		new Theme(Theme.THEME_PAPER_BACK_16, R.drawable.paper_back_sixteen),
		new Theme(Theme.THEME_ALL, R.drawable.paper_back_one)
	};

	public Theme(int id, int paper) {
		mId = id;
		mPaper = paper;
	}
	
	public Bitmap getPaper(Context context) {
		synchronized (sPaperBitmap) {
			Bitmap paper = sPaperBitmap.get(mPaper);
			if (paper == null) {
				paper = BitmapFactory.decodeResource(context.getResources(), mPaper);
				sPaperBitmap.put(mPaper, paper);
			}
			return paper;
		}
	}
}
